<template>
    <div>
        <!-- 登录弹窗 -->
        <div class="modal-mask"></div>
        <div class="modal-dialog">
        <div class="modal-content">
            <img class="img" src="../../static/images/login-entry.png">
            <div class="content-text">
            <p class="key-bold">神器在手，自律我有！</p>
            <p class="key-bold">自律在手，健康我有！</p>
            <p class="little-tip">举例子：</p>
            <p class="little-content">午饭没有吃麻辣烫，加5分</p>
            <p class="little-content">晚饭没有忍住T_T，扣5分</p>
            </div>
        </div>
        <div class="modal-footer">
            <button open-type="getUserInfo" lang="zh_CN" class="btn" @getuserinfo="login">授权登录</button>
        </div>
        </div>
    </div>
</template>

<script>
import config from '../config'
import qcloud from 'wafer2-client-sdk'
import { showSuccess } from '../util'
export default {
  methods: {
    login () {
      qcloud.setLoginUrl(config.loginUrl)
      qcloud.login({
        success: userInfo => {
          console.log('登录成功', userInfo)
          // 登录成功调用登录成功方法并传递用户信息
          this.loginSuccess(userInfo)
          // 使用$emit向父组件传递false和userinfo两个参数
          this.$emit('changeShow', false, userInfo)
          // 登录成功显示tabbar
          wx.showTabBar()
          // 调用showToast
          showSuccess('登录成功')
        },
        fail: err => {
          console.log('登录失败', err)
        }
      })
    },
    // 调用登录成功方法
    loginSuccess (userInfo) {
      // 将用户信息保存到微信缓存中
      wx.setStorageSync('userinfo', userInfo)
    }
  }
}
</script>

<style scoped>
.modal-mask {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: #000;
  opacity: 0.5;
  overflow: hidden;
  z-index: 9000;
  color: #fff;
}
.modal-dialog {
  box-sizing: border-box;
  width: 560rpx;
  overflow: hidden;
  position: fixed;
  top: 30%;
  left: 0;
  z-index: 9999;
  background: #fff;
  margin: -150rpx 95rpx;
  border-radius: 16rpx;
}
.modal-content {
  box-sizing: border-box;
  display: flex;
  padding: 0rpx 53rpx 50rpx 53rpx;
  font-size: 32rpx;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.content-tip {
  text-align: center;
  font-size: 36rpx;
  color: #333333;
}
.content-text {
  height:130px;
  padding:10px 0px 50px 0px;
  font-size:14px;
}
.modal-footer {
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  border-top: 1px solid #e5e5e5;
  font-size: 16px;
  font-weight:bold;
  height: 45px;
  line-height: 45px;
  text-align: center;
  background:#feb600;
}
button {
  width: 100%;
  background:#feb600;
  color:#FFFFFF;
  font-weight:bold;
}
.img {
  width: 280px;
  height:90px;
}
.little-tip {
  padding-top:15px;
  padding-bottom:3px;
  font-size: 17px;
  font-weight:bold;
  color: #feb600;
}
.little-content {
  padding-top:5px;
  font-size: 16px;
  color:#606060;
}
.key-bold {
  padding-top:5px;
  font-size: 17px;
  font-weight:bold;
}
</style>
